
---  打赏返利  


local Util = require("common.Util")
local ObjHuman = require("core.ObjHuman")
local RechBackExcel = require("excel.present").rechargeBack
local Msg = require("core.Msg")
local Grid = require("bag.Grid")
local ItemDefine = require("bag.ItemDefine")
local BuyLogic = require("topup.BuyLogic")
local BagLogic = require("bag.BagLogic")
local YunYingLogic = require("yunying.YunYingLogic")
local PanelDefine = require("broadcast.PanelDefine")
local YyHandler = require("yunying.Handler")
local KingWorldLogic = require("present.KingWorldLogic")

local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
local RoleSystemDefine = require("roleSystem.RoleSystemDefine")

function query(human)
    local msgRet = Msg.gc.GC_RECHARGE_BACK_QUERY
    msgRet.recharge = human.db.topupAcount or 0
    msgRet.maxCnt = #RechBackExcel
    msgRet.isEnd = 0

    local len = 0
    local getDb = human.db.rechargeBackGet or {}
    for k, config in ipairs(RechBackExcel) do
        len = len + 1
        local net = msgRet.list[len]
        net.id = k
        net.need = config.need
        net.state = getDb[k] and 2 or 0
        for j, h in ipairs(config.items) do
            Grid.makeItem(net.reward[j], h[1], h[2])
        end
        net.reward[0] = #config.items

        if len >= 10 then
           msgRet.isEnd = 0
           msgRet.list[0] = len
           Msg.send(msgRet, human.fd)
           len = 0
        end

        if k >= 3 and (not human.db.topupAcount or human.db.topupAcount < config.need) then
            break
        end
    end

    msgRet.isEnd = 1
    msgRet.list[0] = len
    Msg.send(msgRet, human.fd)
end


function get(human, id)
    local config = RechBackExcel[id]
    if not config then return end
    local rechargeNum = human.db.topupAcount or 0
    if config.need > rechargeNum then
        return 
    end

    if human.db.rechargeBackGet and human.db.rechargeBackGet[id] then 
        return 
    end
    
    human.db.rechargeBackGet =  human.db.rechargeBackGet or {}
    human.db.rechargeBackGet[id] = 1

    BagLogic.addItemList(human, config.items,  "rechargeBack")

    query(human)

    RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_108)
end



function isDot(human)
    local getDb = human.db.rechargeBackGet or {}
    local rechargeNum = human.db.topupAcount or 0
    for k, config in ipairs(RechBackExcel) do
        if rechargeNum >= config.need and not getDb[k] then
            return true
        elseif rechargeNum < config.need then
            break
        end
    end
    return false
end



function isRed(human,YYInfo, funcConfig)
    local getDb = human.db.rechargeBackGet or {}
    local rechargeNum = human.db.topupAcount or 0
    for k, config in ipairs(RechBackExcel) do
        if rechargeNum >= config.need and not getDb[k] then
            return true
        elseif rechargeNum < config.need then
            break
        end
    end
    return false
end



function isOpen(human, YYInfo, funcConfig)
    return true
end




